
// 查询类型
const SEARCH_TYPE = {
    NODE: 'node',
    EVENT: 'event'
};
// 工具类
var RaUtil = {
    generateNodeSearch: function(sdData){
        let options = [],
            nodeSdOptions = [];
        let nodeSdNames = Object.keys(sdData.node.impl);
        for(let curName of nodeSdNames){
            let curTitle = sdData.node.impl[curName].title;
            nodeSdOptions.push({key:curName,name:curTitle});
        }
        options.push({'label':'节点类型',
                      'type': 'select',
                      'key':'nodeName',
                      'value':'',
                      'options': nodeSdOptions});
        return options;
    },
    // 提取查询项
    extractSeachOption: function(configData){
        let options = [];
        // 若未指定查询起点则没有查询条件
        if(!configData.searchStart)return options;
        switch (configData.searchStart) {
            case SEARCH_TYPE.NODE:
                options = this.generateNodeSearch(configData.searchSd);
                break;
            default:

        }
        return options;
    },
    // 克隆对象
    cloneObject: function(objectToBeCloned){
        // Basis.
		if (!(objectToBeCloned instanceof Object)) {
			return objectToBeCloned;
		}
		let objectClone = null;
		// Filter out special objects.
		let Constructor = objectToBeCloned.constructor;
		switch (Constructor) {
			// Implement other special objects here.
			case RegExp:
				objectClone = new Constructor(objectToBeCloned);
				break;
			case Date:
				objectClone = new Constructor(objectToBeCloned.getTime());
				break;
			default:
				objectClone = new Constructor();
		}
		// Clone each property.
		for (const prop of Object.keys(objectToBeCloned)) {
			objectClone[prop] = RaUtil.cloneObject(objectToBeCloned[prop]);
		}

		return objectClone;
    }
};

module.exports = RaUtil;
